package com.beimihu.leetcode;

import java.util.HashSet;
import java.util.Set;

public class LengthOfLongestSubstring {
    public int lengthOfLongestSubstring(String s) {
        int len = s.length();
        char[] ss = s.toCharArray();

        int res = 0;
        Set<Character> set = new HashSet<>();
        for (int start = 0 , end = 0; end < len; end++){
            char ch = ss[end];

            while(set.contains(ch)){
                set.remove(ss[start]);
                start++;
            }
            set.add(ss[end]);
            res = Math.max(res,end - start + 1);
        }
        return res;
    }
}
